﻿<?php require_once("includes/session.php"); ?>
<?php confirm_logged_in(); ?>
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php access_check(1,$connection); ?>
<?php include("includes/header.php"); ?>

<?php 
	
	
	
	
	
	function pazeidimai($datestart, $dateend, $burys, $pazeidrusysid, $connection){
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `pazeidrusysid` = ";
	$query .="'".$pazeidrusysid."'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);}

	function nuobaudos($datestart, $dateend, $burys, $nuobrusysid, $connection){
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `nuobrusysid` = ";
	$query .="'".$nuobrusysid."'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);}
	
	function vieta($datestart, $dateend, $burys, $vieta, $connection){
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `vieta` = ";
	$query .="'".$vieta."'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);}
	
	
	function pazeidimai_sum($datestart, $dateend, $burys, $pazeidrusysid, $connection){
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'";
			
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `pazeidrusysid` = ";
	$query .="'".$pazeidrusysid."'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);}

	function nuobaudos_sum($datestart, $dateend, $burys, $nuobrusysid, $connection){
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'";
			
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `nuobrusysid` = ";
	$query .="'".$nuobrusysid."'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);}
	
	function vieta_sum($datestart, $dateend, $burys, $vieta, $connection){
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'";
			
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `vieta` = ";
	$query .="'".$vieta."'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);}
?>

<article>
	<h3>Įstaigoje esančių asmenų drausmės bei taikytų jų atžvilgiu drausminių priemonių ataskaita</h3>
	
    <?php
	
	if (isset($_POST['submit'])){
	$datestart=$_POST['nuo'];
	$dateend=$_POST['iki'];
	echo "
    <table width=\"98%\" border=\"1\">
  <tr>
    <td rowspan=\"3\" align=\"center\" valign=\"middle\">Būrys</td>
    <td rowspan=\"3\" align=\"center\" valign=\"middle\">Būrio viršininkas</td>
    <td rowspan=\"3\" align=\"center\" valign=\"middle\">Viso</td>
    <td rowspan=\"3\" align=\"center\" valign=\"middle\">Skirta</td>
    <td colspan=\"7\" align=\"center\" valign=\"middle\">Drausmės pažeidimai</td>
    <td colspan=\"6\" align=\"center\" valign=\"middle\">Padaryti drausmės pažeidimai</td>
    <td colspan=\"8\" align=\"center\" valign=\"middle\">Taikytos nuobaudos</td>
    </tr>
  <tr>
    <td align=\"center\" valign=\"middle\"><small>Fizinio smurto naudo- jimas</small></td>
    <td align=\"center\" valign=\"middle\"><small>Alkoholinių gėrimų vartojimas</small></td>
    <td align=\"center\" valign=\"middle\"><small>Nark. maedž. vartoj.</small></td>
    <td align=\"center\" valign=\"middle\"><small>Psich. medž. vartoj.</small></td>
    <td align=\"center\" valign=\"middle\"><small>Uždraust. daiktai</small></td>
    <td align=\"center\" valign=\"middle\"><small>Įstaigos nust. tvark. nesilaik.</small></td>
    <td align=\"center\" valign=\"middle\"><small>Administr. reikalavimų nevykdym.</small></td>
    <td align=\"center\" valign=\"middle\"><small>Darb. objekt. įst. terit.</small></td>
    <td align=\"center\" valign=\"middle\"><small>Darb. objekt. už įst. terit.</small></td>
    <td align=\"center\" valign=\"middle\"><small>06:00 iki 18:00</small></td>
    <td align=\"center\" valign=\"middle\"><small>18:00 iki 22:00</small></td>
    <td align=\"center\" valign=\"middle\"><small>22:00 iki 06:00</small></td>
    <td align=\"center\" valign=\"middle\"><small>Šv. ir poilsio dienom</small></td>
    <td align=\"center\" valign=\"middle\"><small>Papei- kimas</small></td>
    <td align=\"center\" valign=\"middle\"><small>Budėjim. be eilės</small></td>
    <td align=\"center\" valign=\"middle\"><small>Uždrausti 1 mėn. pirkti maisto prod.</small></td>
    <td align=\"center\" valign=\"middle\"><small>Uždar. į B.I.</small></td>
    <td align=\"center\" valign=\"middle\"><small>Perkėl. į KTP</small></td>
    <td align=\"center\" valign=\"middle\"><small>Perkėlim. iš lengv. gr. į paprast.</small></td>
    <td align=\"center\" valign=\"middle\"><small>Perkėlim. iš paprast. gr. į drausmės</small></td>
    <td align=\"center\" valign=\"middle\"><small>Perkeltas iš KTP į kalėjimą</small></td>
  </tr>
  <tr>
    <td align=\"center\" valign=\"middle\"><strong>5.1</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>5.2</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>5.3</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>5.4</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>5.5</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>5.6</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>5.7</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>6.1</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>6.2</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>6.3</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>6.4</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>6.5</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>6.6</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>7.1</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>7.2</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>7.3</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>7.4</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>7.5</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>7.6</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>7.7</strong></td>
    <td align=\"center\" valign=\"middle\"><strong>7.8</strong></td>
  </tr> "; 

  
	$query = "SELECT *";
	$query .= " FROM `buriai`";
	$r = mysql_query($query, $connection);
	confirm_query($r);
	print_r ($result_set);
	//$subject = mysql_fetch_array($result_set);
	while ($bur = mysql_fetch_array($r)) {
	//print_r ($bur);
	$burys=$bur['burys'];
 echo "<tr>
    <td align=\"center\">";
	echo $burys;
 echo "</td>
	
	
	
    <td align=\"left\">" ;
	//burio virsininkas
	$query = "SELECT *";
	$query .= " FROM `buriai`, `personalas`";
	$query .= " WHERE `buriai`.burys = ";
	$query .= $burys;
	$query .= " AND `buriai`.personalasid = `personalas`.personalasid";
	
	//echo $query;
	$result_set = mysql_query($query, $connection);

	$subject = mysql_fetch_array($result_set);
	//print_r ($subject);
	if ($subject['lep']==1){echo "L.e.p. ";};
	echo substr_unicode($subject['vardas'], 0, 1).". ".$subject['pavarde'];
 echo "</td>
	
	
	
    <td align=\"center\">";
	//viso pazeideju
	
	$query ="SELECT COUNT( * ) AS `Rows` , `userid`
FROM `nuobaudos` WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1' GROUP BY `userid`";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	echo "</td>
	
	
	
    <td align=\"center\">";
	//Skirta nuobaudu
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	echo "</td>
	
	
	
    <td align=\"center\">";
	//fizinio smurto naudojimas
	pazeidimai($datestart, $dateend, $burys, '1', $connection);
	
	echo "</td>
		
	
    <td align=\"center\">";
	//Alkonaftai
	pazeidimai($datestart, $dateend, $burys, '2', $connection);
	
	echo "</td>
	
	
    <td align=\"center\">";
	//narikai
	pazeidimai($datestart, $dateend, $burys, '3', $connection);
	
	echo "</td>
	
    <td align=\"center\">";//niuhai
	pazeidimai($datestart, $dateend, $burys, '4', $connection);
	
	echo "</td>
    <td align=\"center\">";//zapretai
	pazeidimai($datestart, $dateend, $burys, '5', $connection);
	
	echo "</td>
    <td align=\"center\">";//bardakai
	pazeidimai($datestart, $dateend, $burys, '6', $connection);
	
	echo "</td>
    <td align=\"center\">";//lempa
	pazeidimai($datestart, $dateend, $burys, '7', $connection);
	
	echo "</td>
	
	
    <td align=\"center\">";//rabocke
	vieta($datestart, $dateend, $burys, '1', $connection);
	
	echo "</td>
    <td align=\"center\">";//atvira
	vieta($datestart, $dateend, $burys, '2', $connection);
	
	echo "</td>
    <td align=\"center\">";//6-18
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `pazeidlaikas` > '06:00:00'";
	$query .=" AND `pazeidlaikas` < '17:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	echo "</td>
    <td align=\"center\">";//18-22
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `pazeidlaikas` > '18:00:00'";
	$query .=" AND `pazeidlaikas` < '21:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	echo "</td>
    <td align=\"center\">";//22-6
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `pazeidlaikas` > '22:00:00'";
	//$query .=" AND `pazeidlaikas` < '05:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	$c = mysql_num_rows($result_set);
	
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	//$query .=" AND `pazeidlaikas` > '22:00:00'";
	$query .=" AND `pazeidlaikas` < '05:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	$b = mysql_num_rows($result_set);
	$a = $b +$c;
	echo $a;
	echo "</td>
	
	
	
    <td align=\"center\">";//iseigines
	$query = "SELECT `nuobaudosid`
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	$query .=" AND DAYNAME(`pazeiddata`) = 'Saturday' OR 'Sunday'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	
	echo "</td>
    <td align=\"center\">";//papeikimas
	nuobaudos($datestart, $dateend, $burys, '1', $connection);
	
	echo "</td>
    <td align=\"center\">";//budejimas
	nuobaudos($datestart, $dateend, $burys, '2', $connection);
	
	echo "</td>
    <td align=\"center\">";//laras
	nuobaudos($datestart, $dateend, $burys, '3', $connection);
	
	echo "</td>
    <td align=\"center\">";//triumas
	nuobaudos($datestart, $dateend, $burys, '4', $connection);
	
	echo "</td>
    <td align=\"center\">";//KTP
	nuobaudos($datestart, $dateend, $burys, '5', $connection);
	
	echo "</td>
    <td align=\"center\">";//lengva -> paprasta
	nuobaudos($datestart, $dateend, $burys, '6', $connection);
	
	echo "</td>
    <td align=\"center\">";//drausmes
	nuobaudos($datestart, $dateend, $burys, '7', $connection);
	
	echo "</td>
    <td align=\"center\">";//KTP - kalejima
	nuobaudos($datestart, $dateend, $burys, '8', $connection);
	
	echo "</td>
  </tr>";
  
  }; 
  
  
  
  
  $burys=0;
 echo "<tr>
    <td colspan=\"2\" align=\"center\">";
	echo Karantinas;
 echo "</td>
	
	
	
    
	
	
	
    <td align=\"center\">";
	//viso pazeideju
	
	$query ="SELECT COUNT( * ) AS `Rows` , `userid`
FROM `nuobaudos` WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1' GROUP BY `userid`";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	echo "</td>
	
	
	
    <td align=\"center\">";
	//Skirta nuobaudu
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	echo "</td>
	
	
	
    <td align=\"center\">";
	//fizinio smurto naudojimas
	pazeidimai($datestart, $dateend, $burys, '1', $connection);
	
	echo "</td>
		
	
    <td align=\"center\">";
	//Alkonaftai
	pazeidimai($datestart, $dateend, $burys, '2', $connection);
	
	echo "</td>
	
	
    <td align=\"center\">";
	//narikai
	pazeidimai($datestart, $dateend, $burys, '3', $connection);
	
	echo "</td>
	
    <td align=\"center\">";//niuhai
	pazeidimai($datestart, $dateend, $burys, '4', $connection);
	
	echo "</td>
    <td align=\"center\">";//zapretai
	pazeidimai($datestart, $dateend, $burys, '5', $connection);
	
	echo "</td>
    <td align=\"center\">";//bardakai
	pazeidimai($datestart, $dateend, $burys, '6', $connection);
	
	echo "</td>
    <td align=\"center\">";//lempa
	pazeidimai($datestart, $dateend, $burys, '7', $connection);
	
	echo "</td>
	
	
    <td align=\"center\">";//rabocke
	vieta($datestart, $dateend, $burys, '1', $connection);
	
	echo "</td>
    <td align=\"center\">";//atvira
	vieta($datestart, $dateend, $burys, '2', $connection);
	
	echo "</td>
    <td align=\"center\">";//6-18
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `pazeidlaikas` > '06:00:00'";
	$query .=" AND `pazeidlaikas` < '17:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	echo "</td>
    <td align=\"center\">";//18-22
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `pazeidlaikas` > '18:00:00'";
	$query .=" AND `pazeidlaikas` < '21:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	echo "</td>
    <td align=\"center\">";//22-6
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `pazeidlaikas` > '22:00:00'";
	//$query .=" AND `pazeidlaikas` < '05:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	$c = mysql_num_rows($result_set);
	
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	//$query .=" AND `pazeidlaikas` > '22:00:00'";
	$query .=" AND `pazeidlaikas` < '05:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	$b = mysql_num_rows($result_set);
	$a = $b +$c;
	echo $a;
	echo "</td>
	
	
	
    <td align=\"center\">";//iseigines
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'
			AND `burys` = ";
	$query .= "'".$burys."'";
	$query .=" AND `istaiga` = '1'";
	$query .=" AND DAYNAME(`pazeiddata`) = 'Saturday' OR 'Sunday'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	
	echo "</td>
    <td align=\"center\">";//papeikimas
	nuobaudos($datestart, $dateend, $burys, '1', $connection);
	
	echo "</td>
    <td align=\"center\">";//budejimas
	nuobaudos($datestart, $dateend, $burys, '2', $connection);
	
	echo "</td>
    <td align=\"center\">";//laras
	nuobaudos($datestart, $dateend, $burys, '3', $connection);
	
	echo "</td>
    <td align=\"center\">";//triumas
	nuobaudos($datestart, $dateend, $burys, '4', $connection);
	
	echo "</td>
    <td align=\"center\">";//KTP
	nuobaudos($datestart, $dateend, $burys, '5', $connection);
	
	echo "</td>
    <td align=\"center\">";//lengva -> paprasta
	nuobaudos($datestart, $dateend, $burys, '6', $connection);
	
	echo "</td>
    <td align=\"center\">";//drausmes
	nuobaudos($datestart, $dateend, $burys, '7', $connection);
	
	echo "</td>
    <td align=\"center\">";//KTP - kalejima
	nuobaudos($datestart, $dateend, $burys, '8', $connection);
	
	echo "</td>
  </tr>";
  echo "<tr>
    <td colspan=\"2\" align=\"right\"><strong>Viso</strong></td>
    <td align=\"center\">";
	//viso pazeideju
	
	$query ="SELECT COUNT( * ) AS `Rows` , `userid`
FROM `nuobaudos` WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'";
			
	$query .=" AND `istaiga` = '1' GROUP BY `userid`";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	echo "</td>
	
	
	
    <td align=\"center\">";
	//Skirta nuobaudu
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'";
			
	$query .=" AND `istaiga` = '1'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	echo "</td>
	
	
	
    <td align=\"center\">";
	//fizinio smurto naudojimas
	pazeidimai_sum($datestart, $dateend, $burys, '1', $connection);
	
	echo "</td>
		
	
    <td align=\"center\">";
	//Alkonaftai
	pazeidimai_sum($datestart, $dateend, $burys, '2', $connection);
	
	echo "</td>
	
	
    <td align=\"center\">";
	//narikai
	pazeidimai_sum($datestart, $dateend, $burys, '3', $connection);
	
	echo "</td>
	
    <td align=\"center\">";//niuhai
	pazeidimai_sum($datestart, $dateend, $burys, '4', $connection);
	
	echo "</td>
    <td align=\"center\">";//zapretai
	pazeidimai_sum($datestart, $dateend, $burys, '5', $connection);
	
	echo "</td>
    <td align=\"center\">";//bardakai
	pazeidimai_sum($datestart, $dateend, $burys, '6', $connection);
	
	echo "</td>
    <td align=\"center\">";//lempa
	pazeidimai_sum($datestart, $dateend, $burys, '7', $connection);
	
	echo "</td>
	
	
    <td align=\"center\">";//rabocke
	vieta_sum($datestart, $dateend, $burys, '1', $connection);
	
	echo "</td>
    <td align=\"center\">";//atvira
	vieta_sum($datestart, $dateend, $burys, '2', $connection);
	
	echo "</td>
    <td align=\"center\">";//6-18
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'";
			
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `pazeidlaikas` > '06:00:00'";
	$query .=" AND `pazeidlaikas` < '17:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	echo "</td>
    <td align=\"center\">";//18-22
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'";
			
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `pazeidlaikas` > '18:00:00'";
	$query .=" AND `pazeidlaikas` < '21:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	echo "</td>
    <td align=\"center\">";//22-6
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'";
			
	$query .=" AND `istaiga` = '1'";
	$query .=" AND `pazeidlaikas` > '22:00:00'";
	//$query .=" AND `pazeidlaikas` < '05:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	$c = mysql_num_rows($result_set);
	
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'";
			
	$query .=" AND `istaiga` = '1'";
	//$query .=" AND `pazeidlaikas` > '22:00:00'";
	$query .=" AND `pazeidlaikas` < '05:59:59'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	$b = mysql_num_rows($result_set);
	$a = $b +$c;
	echo $a;
	echo "</td>
	
	
	
    <td align=\"center\">";//iseigines
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'";
			
	$query .=" AND `istaiga` = '1'";
	$query .=" AND DAYNAME(`pazeiddata`) = 'Saturday' OR 'Sunday'";
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	
	
	echo "</td>
    <td align=\"center\">";//papeikimas
	nuobaudos_sum($datestart, $dateend, $burys, '1', $connection);
	
	echo "</td>
    <td align=\"center\">";//budejimas
	nuobaudos_sum($datestart, $dateend, $burys, '2', $connection);
	
	echo "</td>
    <td align=\"center\">";//laras
	nuobaudos_sum($datestart, $dateend, $burys, '3', $connection);
	
	echo "</td>
    <td align=\"center\">";//triumas
	nuobaudos_sum($datestart, $dateend, $burys, '4', $connection);
	
	echo "</td>
    <td align=\"center\">";//KTP
	nuobaudos_sum($datestart, $dateend, $burys, '5', $connection);
	
	echo "</td>
    <td align=\"center\">";//lengva -> paprasta
	nuobaudos_sum($datestart, $dateend, $burys, '6', $connection);
	
	echo "</td>
    <td align=\"center\">";//drausmes
	nuobaudos_sum($datestart, $dateend, $burys, '7', $connection);
	
	echo "</td>
    <td align=\"center\">";//KTP - kalejima
	nuobaudos_sum($datestart, $dateend, $burys, '8', $connection);
	
	echo "</td>
  </tr>
 
  <tr>
    <td colspan=\"4\">&nbsp;</td>
    <td colspan=\"7\" align=\"center\">";
	$query = "SELECT *
			FROM `nuobaudos`
			WHERE `svarstdata` >= ";
	$query .= "'".$datestart."'";
	$query .=" AND `svarstdata` <= ";
	$query .= "'".$dateend."'";
	$query .=" AND `nuobrusysid` != '9'
			AND `nuobrusysid` != '20'";
			
	$query .=" AND `istaiga` = '1'";
	
	//echo $query;
	$result_set = mysql_query($query, $connection);
	echo mysql_num_rows($result_set);
	echo "
	</td>
    <td colspan=\"5\" align=\"center\">";
	echo mysql_num_rows($result_set);
	echo "</td>
    <td align=\"center\">&nbsp;</td>
    <td colspan=\"8\" align=\"center\">";
	echo mysql_num_rows($result_set);
	echo "</td>
    </tr>
</table>"; }?>
<br>

<form action="ataskaita_drausmes.php" method="post">
	
<table  border="0">
  <tr>
    <td>Nuo&nbsp;</td>
    <td><input name="nuo" type="date">&nbsp;</td>
  </tr>
  <tr>
    <td>Iki&nbsp;</td>
    <td><input name="iki" type="date">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input name="submit" type="submit" value="Magic">&nbsp;</td>
  </tr>
</table>

</form>
</article>
				
            
<?php require("includes/footer.php"); ?>